class_name HitboxComponent
extends Area2D

signal on_hit_hurtbox(hurtbox: HurtboxComponent)

var damage := 1.0
var critical := false
var knockback_power := 1.0
var source: Node2D = null

func enable() -> void:
	set_deferred("monitoring", true)
	set_deferred("monitorable", true)
	
func disable() -> void:
	set_deferred("monitoring", false)
	set_deferred("monitorable", false)

func setup(context_damage: float, context_critical: bool, context_knockback_power: float, context_source: Node2D) -> void:
	damage = context_damage
	critical = context_critical
	knockback_power = context_knockback_power
	source = context_source


func _on_area_entered(area: Area2D) -> void:
	if area is HurtboxComponent:
		SoundManager.player_sound(SoundManager.Sound.HIT)
		on_hit_hurtbox.emit(area)
